$(document).ready(function(){  
	$("#functionNav").attr("href",navAddr);
	//获取查询条件
	var params =$("#form1").serializeObject();
/*	 for (var sProp in params) {
		 if(params[sProp]=="" || params[sProp]==null ){
				delete params[sProp];
			}
	 }*/
    //初始化出退库单据Table
	createTable('#ctkDjTable',ProjectName+'/colmanage.getDjList.do','id',ctkDjColTitle,params);	
	var cpData = ajaxResult("get",false,ProjectName+"/colmanage.getDjList.do",params);
	for(i=0;i<cpData.rows.length;i++){
		if(cpData.rows[i].hasSub==true){			
			$('#bt_'+i).parents().children("td").eq(0).children("a").show();
		}else{
			$('#bt_'+i).parents().children("td").eq(0).children("a").hide();
		}
	}
	//点击查询按钮
	 $("#search_btn").click(function(){
		 refreshTable('#ctkDjTable','#form1');
	 });
})
InitSubTable = function (index, row, $detail) {
	var djbh = row.id;
	var djzt = $("#djzt").val();
	var params =$("#form1").serializeObject();
	var cur_table = $detail.html('<table id="table'+djbh+'"></table>').find('table');
	var subData = ajaxResult("get",false,ProjectName+"/colmanage.getSubDjList.do?djbh="+escape(djbh)+"&djzt="+djzt,params);
	$(cur_table).bootstrapTable({
		data:subData.rows,
		clickToSelect: true,
		detailView: false,//父子表
		queryParams: {djbh:djbh,djzt:djzt},
		uniqueId: "id",
		pagination: false,
		columns: ctkDjColTitle
	});
}

var ctkDjColTitle = [{
	        field: 'id',
	        title: '申请单号'
	    },{
	        field: 'bt',
	        title: '标题',
	        formatter: function(value, row, index) {
	        	//this.eq(0).children("a").show();
	        	if(row.djzt == 0){
		      	  return '<a id="bt_'+index+'" href="ctkKfList.html?djbh='+escape(row.id)+'&cgbz='+row.cgbz+'&lsbz='+row.lsbz+'&canreuse='+row.canreuse+'">'+value+'</a>';
		      	}else{
		      		return value;
		      	}
	    	}
	    },{
	        field: 'tyyy',
	        title: '提用原因'
	    },{
	        field: '',
	        title: '出库类型',
	        formatter: function(value, row, index) {
	        	var result = "";
	        	if(row.cgbz == 1){
	        		result = "出馆";
	        	}else if(row.lsbz == 1){
	        		result ="临时提用";
	        	}else{
	        		result = "馆内出库";
	        	}
	        	return result;		      	  
		    }
	    },{
	        field: 'yjcksj',
	        title: '预计出库时间',
	        formatter: function(value, row, index) {
	        	var result = "";
	        	if(value!=null && value!='')
	        		result = value.split(' ')[0];
	        	return result;		      	  
		    }
	    },{
	        field: 'yjtksj',
	        title: '预计退库时间',
	        formatter: function(value, row, index) {
	        	var result = "";
	        	if(value!=null && value!='')
	        		result = value.split(' ')[0];
	        	return result;		      	  
		    }
	    },{ 
	        field: 'sqbmmc',
	        title: '申请部门'
	    },{
	        field: 'sqrmc',
	        title: '申请人'
	    },{
	        field: 'sqrq',
	        title: '申请日期',
	        formatter: function(value, row, index) {
	        	var result = "";
	        	if(value!=null && value!='')
	        		result = value.split(' ')[0];
	        	return result;		      	  
		    }
	    },{
	        field: 'gdsj',
	        title: '申请通过日期',
	        formatter: function(value, row, index) {
	        	var result = "";
	        	if(value!=null && value!='')
	        		result = value.split(' ')[0];
	        	return result;		      	  
		    }
	    },{
	        field: 'djzt',
	        title: '单据状态',
	        formatter: function(value, row, index) {
	        	if(value == 1){
		      	  return '完成';
		      	}else{
		          return '未完成';
		      	}
	        }
}]